package com.ktjy.controller;

import com.ktjy.service.IUploadService;
import com.ktjy.utils.AjaxResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/file")
@Slf4j
@Tag(name = "文件上传")
public class UploadController {
    @Autowired
    IUploadService uploadService;

    @PostMapping("/upload")
    @Tag(name = "文件上传")
    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file){
        try {
            String fileName=uploadService.upload(file);
            return AjaxResult.success("文件上传成功"+fileName);
        } catch (Exception e) {
            log.error("文件上传失败",e);
            return AjaxResult.error("文件上传失败");
        }
    }
}
